home *** CD-ROM | disk | FTP | other *** search
- 10 gosub60100:clr
- 20 :
- 30 n=50: :rem number of elements
- 40 dim a(n): :rem array of random
- 50 :
- 80 na$(1)="standard"
- 81 na$(2)="flags"
- 82 na$(3)="wrinkle"
- 83 na$(4)="simple"
- 84 na$(5)="m-search"
- 90 goto5000
- 97 :
- 98 : standard bubble sort
- 99 :
- 100 fori=n-1to1step-1
- 110 forj=1toi
- 120 ifa(j)<=a(j+1)then140
- 130 t=a(j):a(j)=a(j+1):a(j+1)=t
- 140 nextj
- 150 nexti
- 160 return
- 197 :
- 198 : flags bubble sort
- 199 :
- 200 fori=n-1to1step-1
- 205 f=1
- 210 forj=1toi
- 220 ifa(j)<=a(j+1)then240
- 225 f=0
- 230 t=a(j):a(j)=a(j+1):a(j+1)=t
- 240 nextj
- 245 iffthen260
- 250 nexti
- 260 return
- 297 :
- 298 : wrinkle bubble sort
- 299 :
- 300 fori=1ton-1
- 310 ifa(i)<=a(i+1)then360
- 320 forj=ito1step-1
- 330 ifa(j)<=a(j+1)then360
- 340 t=a(j):a(j)=a(j+1):a(j+1)=t
- 350 nextj
- 360 nexti
- 370 return
- 397 :
- 398 : simple bubble sort
- 399 :
- 400 fori=1ton-1
- 410 forj=i+1ton
- 420 ifa(i)<=a(j)then440
- 430 t=a(i):a(i)=a(j):a(j)=t
- 440 nextj
- 450 nexti
- 460 return
- 497 :
- 498 : m-search bubble sort
- 499 :
- 500 fori=1ton-1:m=i
- 510 forj=i+1ton
- 520 ifa(m)>a(j)thenm=j
- 530 nextj
- 540 t=a(i):a(i)=a(m):a(m)=t
- 550 nexti
- 560 return
- 598 :
- 599 :
- 1000 tm=ti/60:rem finishing time
- 1010 fori=1ton
- 1020 printa(i),:next:print
- 1030 print"elapsed time ="tm"seconds"
- 1040 return
- 5000 print"[147] making a better bubble"
- 5010 print" this program will demonstrate five"
- 5020 print"bubble sort routines."
- 5030 print" press space to start demo."
- 5040 ifpeek(203)<>60then5040
- 5050 for loop=1 to 5
- 5060 ti$="000000":i=rnd(-1000):pr$=na$(loop)+" bubble sort"
- 5070 ta=(40-len(pr$))/2:print"[147]"tab(ta)pr$""
- 5080 fori=1ton
- 5090 a(i)=int(rnd(1)*n)
- 5100 printa(i),:next
- 5105 print:print" sorting"n"numbers..."
- 5110 on loop gosub 100,200,300,400,500
- 5115 print"[147]"tab(ta)pr$""
- 5116 fori=1ton
- 5117 printa(i),:next
- 5120 tm(loop)=ti/60:print:print"it took"tm(loop)"seconds to sort"
- 5130 print"using the "pr$" routine."
- 5140 print" press space to continue."
- 5150 ifpeek(203)<>60then5150
- 5160 next
- 5170 print"[147] making a better bubble"
- 5180 print" summary of demos"
- 5190 print"type of sort"tab(20)"time"
- 5200 print"[192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192]"
- 5210 for loop=1 to 5
- 5220 printna$(loop)tab(20)tm(loop)
- 5230 next
- 5240 print"[192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192]"
- 5250 print"press space to see demo again; press"
- 5260 print"return to return to loadstar."
- 5270 a=peek(203):ifa<>60anda<>1then5270
- 5280 ifa=60thenrun30
- 5290 open15,8,15,"r0:hello connect=hello connect":input#15,er:close15
- 5300 ifer<>63thenend
- 5310 load"hello connect",8
- 59999 stop
- 60100 poke53280,14:poke53281,14
- 60110 printchr$(142)"[147][213][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][201]";
- 60120 fora=1to23:print"[221]"spc(38)"[221]";:next
- 60130 print"[202][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][203][157][148][192]"
- 60140 fora=217to242:pokea,peek(a)or128:next
- 60150 print" loadstar presents:"
- 60160 print" "
- 60170 print" making a better bubble "
- 60180 print" "
- 60190 print" by royal c. jones "
- 60200 print" "
- 60210 print" copyright 1987 "
- 60220 print" "
- 60230 print" "
- 60240 print" press space to continue."
- 60250 ifpeek(203)<>60then60250
- 60260 return
-